let ajaxCount = 0

export const request = (params) => {
  //发起一次请求就让ajaxCount加一
  ajaxCount += 1
  wx.showLoading({
    title: '加载中',
  })

  return new Promise((res, rej) => {
      const baseUrl = "https://api-hmugo-web.itheima.net/api/public/v1"
    //   http://111.67.198.176:8112
      //   https://api-hmugo-web.itheima.net/api/public/v1
      wx.request({
        ...params,
        url:  baseUrl + params.url,
        success: (result) => {
          res(result.data.message)
        },
        fail: (err) => {
          rej(err)
        },
        complete: () => {
          ajaxCount -= 1
          if(ajaxCount === 0) {
            wx.hideLoading()
          }
        }
      })
  })
}